package com.ruoyi.data.modbus;

import com.ruoyi.machine.advanced.status.service.IStatusService;
import com.ruoyi.machine.base.device.service.IDeviceService;
import com.ruoyi.produce.base.circulatingWater.service.ICirculatingWaterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

@Component
@Controller
@Order(value = 2)
public class ModbusController implements CommandLineRunner {
    @Autowired
    private IStatusService statusService;
    @Autowired
    private IDeviceService deviceService;
    @Autowired
    private ICirculatingWaterService circulatingWaterService;

    public void test() {
        System.out.println("modbus开始测试");
        Thread thread = new Thread(() -> {
            while (true) {
                System.out.println("modbus设备开始读数据");
                Modbus4jRunner.collectData(statusService, circulatingWaterService, deviceService);
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
    }

    @Override
    public void run(String... args) throws Exception {
//        test();
    }
}
